package com.bgs.engineering.util.pageUtil;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * 分页助手
 * @auther zcy
 * @date 2021/10/27 14:47
 */
public class MybatisPageHelper {

    /**
     * 将分页的开始页、数量进行封装
     *
     * @param pageRequest
     */
    public static void startPage(PageRequest pageRequest) {
        PageHelper.startPage(pageRequest.getPageNum(), pageRequest.getPageSize());
    }
    /**
     * 生成分页结果集
     *
     * @param list
     * @return
     */
    public static PageResult getPageResult(List<?> list) {
        PageInfo pageInfo = new PageInfo(list);
        PageResult pageResult = new PageResult();
        pageResult.setPageNum(pageInfo.getPageNum());
        pageResult.setPageSize(pageInfo.getPageSize());
        pageResult.setTotalSize(pageInfo.getTotal());
        pageResult.setTotalPages(pageInfo.getPages());
        pageResult.setContent(pageInfo.getList());
        return pageResult;
    }

}
